<template>
  <div>
    <home-header></home-header>
    <home-swiper :list="data.swiperList"></home-swiper>
    <home-icons :list="data.iconList"></home-icons>
    <home-recommend :list="data.recommendList"></home-recommend>
    <home-weekends :list="data.weekendList"></home-weekends>
  </div>
</template>

<script>
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/Icons'
import HomeRecommend from './components/Recommend'
import HomeWeekends from './components/Weekends'
import axios from 'axios'
import { reactive, onMounted } from 'vue'
import { useStore } from 'vuex'
export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekends
  },
  setup() {
    let data = reactive({
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: [],
    })
    let store = useStore()
    let city = store.state.city

    async function getData () {
      let res = await axios.get('/api/index.json?city=' + city)
      let result = res.data
      if (result.ret && result.data) {
        result = result.data
        data.swiperList = result.swiperList
        data.iconList = result.iconList
        data.recommendList = result.recommendList
        data.weekendList = result.weekendList
      }
    }
    onMounted(()=>{
        getData()
    })
    return { data }
  }
}
</script>
